#coding:utf8
from flask import Flask,jsonify,render_template,url_for
from flask import request
from flask import redirect

import flask
import os
import sys
#导入文件
# import config

#apppath = os.path.dirname(os.path.abspath(__file__))

app = Flask(__name__)
#开启DEBUG模式

app.debug = True
# app.config['DEBUG'] = True

#加载配置文件
# app.config.from_pyfile('configs.py')
# app.config.from_object('configs')
#读取配置文件，silent=True，则文件不存在时会默默退出，不会抛出异常！
# app.config.from_pyfile('config.txt',silent=True)


@app.route('/')
def index():
    context = {
        'username': request.args.get('username'),
        'password': request.args.get('password')
        request.args.__getattribute__()
    }
    return render_template("index.html",**context)

@app.route('/login/',methods=['GET','POST'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] == "admin":
            return redirect(url_for('index',username=request.form['username'],password=request.form['password']))
        else:
            error = 'Invalid username/password'
        # the code below is executed if the request method
        # was GET or the credentials were invalid
    return render_template('login.html', error=error)

#with app.request_context(environ):
 #   assert request.method == 'POST'

if __name__ == '__main__':
    app.run()
